<template>
	<view>
		<view class="search-view">
			<u-search placeholder="输入任务名搜索" bgColor="#fff" :showAction="false" v-model="merge_keyword"
				@change="change"></u-search>
			<!-- <view class="optionSel flex align">
				<view class="flex align" @click="show = true">筛选<uni-icons type="settings" size="20"
						color="#797979"></uni-icons></view>
			</view> -->
		</view>
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="name">{{item.tuiguangtask.title}}</view>
			<view class="info flex between">
				<view class="info1">
					<view class="flex align between">
						<view>矩阵任务</view>
						<view>{{item.tuiguangtask.title}}</view>
					</view>
					<view class="flex align between">
						<view>发布人</view>
						<view>{{item.nickname}}</view>
					</view>
					<view class="flex between">
						<view>评论内容</view>
						<view>{{item.content}}</view>
					</view>
					<view class="flex between">
						<view>评论时间</view>
						<view>{{item.create_time}}</view>
					</view>
					<view class="flex align between">
						<view>点赞数</view>
						<view>{{item.digg_count}}</view>
					</view>
					<view class="flex align between">
						<view>评论数</view>
						<view>{{item.reply_comment_total}}</view>
					</view>
					<view class="flex align between">
						<view>命中词</view>
						<view>{{item.keyword}}</view>
					</view>
				</view>
				<view class="info2" @click="toReply(item)">
					<view class="reply">
						<view class="re-tit">回复</view>
						<view class="re-con">{{item.reply_content}}</view>
					</view>
					<view class="text1">状态</view>
					<view class="text2"
						:style="item.status==1?'background:#369805':item.status==2?'background:#AFAFAF':'background:#D81E06'">
						{{item.status==1?'未回复':item.status==2?'已回复':'自动回复失败'}}
					</view>
				</view>
			</view>
			<!-- <view class="delBtn flex align">
				<uni-icons type="trash" size="20" color="#fff"></uni-icons>
				删除
			</view> -->
		</view>
		<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
		<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
		<u-popup :show="show" :round="10" mode="bottom">
			<view class="btomShow">
				<view class="closeempty" @click="show = false">
					<uni-icons type="closeempty" size="30"></uni-icons>
				</view>
				<view class="showTit">筛选</view>
				<view class="title">类型</view>
				<view class="flex align between type">
					<view>混剪视频</view>
					<view>普通视频</view>
				</view>
				<view class="title">使用次数</view>
				<view class="flex align between nums">
					<input placeholder="请输入" type="digit" />
					<view>——</view>
					<input placeholder="请输入" type="digit" />
				</view>
				<view class="title">生成时间</view>
				<view class="flex align between nums" @click="show2 = true">
					<input placeholder="请选择" v-model="range[0]" type="digit" disabled />
					<view>——</view>
					<input placeholder="请选择" v-model="range[1]" type="digit" disabled />
				</view>
			</view>
		</u-popup>
		<u-calendar :show="show2" :mode="mode" @confirm="confirm"></u-calendar>
		<u-popup :show="showTan" :round="10" mode="bottom">
			<view class="btomShow">
				<view class="closeempty" @click="showTan = false">
					<uni-icons type="closeempty" size="30"></uni-icons>
				</view>
				<view class="showTit">回复</view>
				<view class="title">评论内容</view>
				<textarea disabled v-model="showContent" ></textarea>
				<view class="title">回复内容</view>
				<textarea v-model="reply_content" placeholder="建议在30个字内"></textarea>
				<view class="subBtn" @click="toReplyCom">确定</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		tuiguangCommentIndex,
		rankDel
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				showTan: false,
				show: false,
				show2: false,
				mode: 'range',
				range: ['', ''],
				current: 0,
				tabs: ['全部', '评论回复', '私信回复'],
				totalPage: 1,
				page: 0,
				offset: 20,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
				merge_keyword: '',
				showContent: '',
				reply_content:''
			};
		},
		onLoad(option) {
			this.getlist();
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		methods: {
			toReply(item) {
				if (item.status == 1) {
					this.showTan = true
					this.showContent = item.content
					this.showId = item.id
				}
			},
			toReplyCom(){
				if (this.reply_content == '') {
					uni.showToast({
						title: '请输入回复内容',
						icon: 'none'
					})
					return false
				}
				let obj = {
					'row[reply_content]': this.reply_content
				}
				let that = this
				uni.request({
					url: 'https://jzxt.jiugezixun.cn/storeadmin/tuiguang_comment/edit/ids/' + that.showId,
					data: obj,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'X-Requested-With': 'XMLHttpRequest',
						'Cookie': uni.getStorageSync('cookies') // 从存储中读取cookies并设置到请求头
					},
					success: result => {
						if (result.data.code == 1) {
							uni.showToast({
								title: '回复成功'
							})
							that.showTan = false
							setTimeout(() => {
								that.showId = ''
								that.reply_content = ''
								that.page = 0
								that.list = []
								that.getlist()
							}, 500)
						} else {
							uni.showToast({
								title: result.data.msg,
								icon:'none'
							})
						}
					},
					fail: result => {
						uni.hideLoading();
					}
				})
			},
			changeTab(index) {
				console.log('当前选中的项：' + index)
				this.current = index
			},
			confirm(e) {
				console.log(e)
				this.range = e
				this.show2 = false
			},
			toUrl() {
				uni.navigateTo({
					url: '/pages/reply/add'
				})
			},
			change() {
				this.page = 0
				this.list = []
				this.getlist()
			},
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
					group_id,
					type,
					merge_keyword,
					statusA,
					rank_id
				} = that;

				let obj = {
					menu_url: 'tuiguang_comment',
					limit: offset,
					offset: page,
					sort: 'id',
					order: 'desc',
					rank_status: 1,
					_: new Date().getTime(),
					filter: {},
					op: {}
					// filter:merge_keyword=='',
					// op:encodeURIComponent(JSON.stringify(filter))
				};
				if (merge_keyword != '') {
					obj.filter = JSON.stringify({
						"tuiguangtask.title": merge_keyword.toString()
					})
					obj.op = JSON.stringify({
						"tuiguangtask.title": '='
					})
				}
				that.status = 'loading';
				if (totalPage > page) {
					let result = await tuiguangCommentIndex(obj);
					that.page = page + 1;
					if (result.total == 0) {
						that.empty = true;
						that.status = 'nomore';
						return;
					}
					that.empty = false;
					setTimeout(() => {
						that.status = 'loadmore';
					}, 500);
					that.list = list.concat(result.rows);
					that.totalPage = Math.ceil(result.total / offset);
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.btomShow {
		padding: 0 28rpx 80rpx;
		position: relative;

		.showTit {
			text-align: center;
			font-size: 32rpx;
			font-weight: bold;
			padding: 33rpx 0;
		}

		input,textarea {
			font-size: 20rpx;
			padding: 16rpx 24rpx;
			border-radius: 10rpx;
			border: solid 1rpx #707070;
			height: 150rpx;
		}

		.closeempty {
			position: absolute;
			top: 20rpx;
			right: 30rpx;

		}

		.title {
			font-size: 28rpx;
			margin: 25rpx 0;
		}

		.subBtn {
			font-size: 30rpx;
			color: white;
			padding: 8rpx 95rpx;
			background: #5D9CEB;
			width: fit-content;
			margin: 80rpx auto 0rpx;
			border-radius: 10rpx;
		}
	}

	.topSearch {
		margin-bottom: 14rpx;

		.addBtn {
			background: #FFCDB8;
			color: white;
			border-radius: 14rpx;
			font-size: 20rpx;
			padding: 8rpx 14rpx;
		}
	}

	.search-view {
		padding: 20rpx 30rpx 0;

		.selOption {
			margin-top: 13rpx;
			background: white;
			padding-right: 20rpx;

			input {
				background: white;
				border-radius: 23rpx;
				font-size: 24rpx;
				padding: 10rpx 20rpx;
			}


		}
	}

	.optionSel {
		color: #797979;
		font-size: 24rpx;
		justify-content: flex-end;
	}

	.list {
		background: white;
		margin: 30rpx;
		border-radius: 12rpx;
		box-shadow: 1rpx 1rpx 8rpx 2rpx gainsboro;

		.name {
			padding: 27rpx 8rpx 8rpx;
			margin: 0 17rpx;
			border-bottom: solid 1rpx #D6D6D6;

			view:nth-child(1) {
				font-size: 28rpx;
				font-weight: bold;
			}

			view:nth-child(2) {
				font-size: 18rpx;
				color: #868686;
			}
		}

		.info {
			padding: 19rpx 17rpx;

			image {
				width: 210rpx;
				height: 117.54rpx;
			}

			.info1 {
				font-size: 20rpx;
				width: 50%;
				border: solid 1rpx #707070;
				margin-left: 30rpx;

				.flex {
					border-bottom: solid 1rpx #707070;
					padding: 4rpx 7rpx;
					font-size: 18rpx;
					text-align: center;

					view {
						flex: 1;
					}
				}


			}

			.info2 {
				text-align: center;
				padding: 0 33rpx;
				width: 48%;

				.reply {
					padding: 5rpx 21rpx;

					.re-tit {
						font-size: 32rpx;
						font-weight: bold;
						text-align: center;
						margin-bottom: 10rpx;
					}

					.re-con {
						border: solid 1rpx #707070;
						padding: 8rpx 14rpx;
						height: 93rpx;
						font-size: 18rpx;

					}
				}

				.text1 {
					color: #424242;
					font-size: 24rpx;
				}

				.text2 {
					font-size: 24rpx;
					background: #369805;
					color: white;
					padding: 3rpx 42rpx;
					border-radius: 33rpx;
					margin: 10rpx auto;
					width: fit-content;
				}
			}

		}

		.delBtn {
			justify-content: center;
			background: #2D2D2D;
			border-radius: 0 0 15rpx 15rpx;
			color: white;
			font-weight: bold;
			padding: 12rpx 0;
		}
	}

	.showTit {
		text-align: center;
		font-size: 32rpx;
		font-weight: bold;
		padding: 33rpx 0;
	}

	.btomShow {
		padding: 0 28rpx 150rpx;
		position: relative;

		.closeempty {
			position: absolute;
			top: 20rpx;
			right: 30rpx;

		}

		.title {
			font-size: 28rpx;
			margin: 25rpx 0;
		}

		.type {
			view {
				background: #F7F7F9;
				width: 313rpx;
				line-height: 61rpx;
				border: solid 1rpx #E7E7E7;
				font-size: 28rpx;
				text-align: center;
				border-radius: 10rpx;
			}
		}

		.nums {
			input {
				width: 290rpx;
				height: 61rpx;
				background: #F7F7F9;
				border: solid 1rpx #E7E7E7;
				border-radius: 10rpx;
				text-align: center;
				font-size: 27rpx;
			}
		}
	}
</style>